package com.fusetech.flow.audit.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fusetech.flow.audit.domain.CurrentAuditNode;
import com.fusetech.flow.audit.mapper.CurrentAuditNodeMapper;
import com.fusetech.flow.audit.service.dto.CurrentAuditNodeDTO;
import com.fusetech.flow.audit.service.mapstruct.CurrentAuditNodeWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 当前审核表Service
 * @author Liuwq
 * @version 2023-05-10
 */
//@DS("zxhy_platform_db")
@Service
@Transactional
public class CurrentAuditNodeService  extends ServiceImpl<CurrentAuditNodeMapper, CurrentAuditNode> {//
	@Autowired
	private CurrentAuditNodeWrapper currentAuditNodeWrapperImpl;

	@Autowired
	private CurrentAuditNodeMapper currentAuditNodeMapper;

	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	public CurrentAuditNodeDTO findById(String id) {
		return currentAuditNodeMapper.findById ( id );
	}

	/**
	 * 自定义分页检索
	 * @param page
	 * @param queryWrapper
	 * @return
	 */
	public IPage <CurrentAuditNodeDTO> findPage(Page<CurrentAuditNodeDTO> page, QueryWrapper queryWrapper) {
		queryWrapper.eq ("a.del_flag", 0 ); // 排除已经删除
		//return  baseMapper.findList (page, queryWrapper);
		System.out.println("nimade1");
		List<CurrentAuditNodeDTO> list = baseMapper.findList(page,queryWrapper).getRecords();
		System.out.println(list.get(0).getDocument());
		return  currentAuditNodeMapper.findList(page, queryWrapper);
	}

	/**
	 * 现在统计数据
	 *
	 * @param queryWrapper 查询包装
	 * @return {@link Long}
	 */
	public Long countNowData(QueryWrapper queryWrapper){
		return  baseMapper.countNowData (queryWrapper);
	}

	/**
	 * 得到当前审计节点dtoby文档id
	 *
	 * @param documentId 文档id
	 * @return {@link CurrentAuditNodeDTO}
	 */
	public CurrentAuditNodeDTO getCurrentAuditNodeDTOByDocumentId(String documentId) {
		QueryWrapper query = new QueryWrapper();
		query.eq("document_id", documentId);
		CurrentAuditNode currentAuditNode = getOne(query);
		CurrentAuditNodeDTO currentAuditNodeDTO = currentAuditNodeWrapperImpl.toDTO(currentAuditNode);
		if(!ObjectUtils.isEmpty(currentAuditNode)){
			currentAuditNodeDTO = findById(currentAuditNode.getId());
		}
		return currentAuditNodeDTO;
	}

	/*public void save(CurrentAuditNode currentAuditNode){

	}

	public void removeById(String id){

	}
	public boolean saveOrUpdate(CurrentAuditNode currentAuditNode){
		return false;
	}

	public void removeByIds(String id){

	}*/

}
